package com.huilian.iotbox.admin.quartz.job;

import com.huilian.iotbox.data.service.ErrorLogCommonService;
import com.huilian.iotbox.data.utils.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 定时删除一个月前的错误日志
 */
@Slf4j
public class ClearDataErrorLogJob implements BaseJob {

    @Autowired
    private ErrorLogCommonService errorLogCommonService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        log.info("--------------定时任务 日志删除开始 时间{}---------------", DateTimeUtils.currTime());
        String time = DateTimeUtils.getSomeDayBeforeStartTime(30);
        log.info("删除" + time + "及以前的报错日志");
        errorLogCommonService.deleteByTime(time);
        log.info("--------------定时任务 日志删除结束 end时间{}---------------", DateTimeUtils.currTime());
    }
}
